/**
 * 
 */
package sn.ugb.cours.jee.zd.hibernate.sessions;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @author zakaria
 */
public class MyHibernateSessionMapper {
	
	private static MyHibernateSessionMapper singleton = null;
	private static final SessionFactory sessionFactory = buildSessionFactory();
	
	private MyHibernateSessionMapper() {
	}
	
	public static MyHibernateSessionMapper getInstance()    {
		if (singleton == null) {
			singleton = new MyHibernateSessionMapper();
		}
		return singleton;
	}
	
	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	
	 private static SessionFactory buildSessionFactory() {
	        try {
	            // Create the SessionFactory from hibernate.cfg.xml
	            return new Configuration().configure().buildSessionFactory();
	        }
	        catch (Throwable ex) {
	            System.err.println("Initial buiding sessionFactory failed." + ex);
	            throw new ExceptionInInitializerError(ex);
	        }
	    }
	

	
}
